import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/resources/str_res_keys.dart';

import '../../../../../components/yt_text_style.dart';
import '../../../../../styles/styles.dart';
///站点编辑评论视图
class RemarkWidget extends StatelessWidget {
  final TextEditingController textFieldController;
  final String? hintString; //占位文字
  final bool? isCanEdit; //是否可以响应输入
  final TextInputType ?textInputType; //输入键盘类型
  final Function(String) ?callBack;
  final bool isUser;
  const RemarkWidget(this.textFieldController,this.callBack,
  {
    this.hintString = '',
    this.textInputType = TextInputType.text,
    this.isCanEdit = true,this.isUser = false,Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<TextInputFormatter> ?inputFormatters = [
      LengthLimitingTextInputFormatter(200)
    ];
    bool textFieldVisibility = false;
    if(isCanEdit == true || (isCanEdit == false && textFieldController.text.isNotEmpty)){
      textFieldVisibility = true;
    }
    return Container(
      color: Colors.white,
      height: 168,
      child: Column(
        children: [
          Container(
            height: 50,
            margin: EdgeInsets.only(left: 16.w),
            alignment: Alignment.centerLeft,
            child:Text(
              ResKey.siteBaseInfoRemark.tr,
              style: ytTextStyle(fontSize: 16, fontWeight: isUser?FontWeight.normal:FontWeight.w500,color: Colour.mainTextColor),
            ),
          ),
          Visibility(
            visible: textFieldVisibility,
              child: Container(
            height: 100,
            margin: EdgeInsets.only(left: 16.w,right: 16.w),
            decoration: const BoxDecoration(
                color: Colour.backgroundColor,
                borderRadius: BorderRadius.all(Radius.circular(4))
            ),
            child: Column(
              children: [
                Container(height: 70,
                  child: TextField(
                    maxLines: 10,
                    textAlign: TextAlign.left,
                    inputFormatters: inputFormatters,
                    style: const TextStyle(fontSize: 14, color: Colour.mainTextColor),
                    controller: textFieldController,
                    keyboardType: textInputType,
                    enabled: isCanEdit,

                    decoration: InputDecoration(
                      border: InputBorder.none,
                      contentPadding: const EdgeInsets.only(left: 10,right: 10,top: 10),
                      hintText: hintString,
                      hintStyle: const TextStyle(
                          fontSize: 14.0,
                          color: Colour.mainTextColor,
                          fontWeight: FontWeight.normal),
                    ),
                    onChanged: (String str) {
                      callBack!(str);

                    },
                  ),),
                Row(
                  children: [
                    Spacer(),
                    Text(
                      textFieldController.text.length.toString(),
                      style: ytTextStyle(fontSize: 12, fontWeight: FontWeight.normal,color:textFieldController.text.isNotEmpty ? Colour.lightTextColor :Colour.diabledButtoBgColor),
                    ),
                    Text(
                      '/200',
                      style: ytTextStyle(fontSize: 12, fontWeight: FontWeight.normal,color: Colour.diabledButtoBgColor),
                    ),
                    Gaps.hGap16
                  ],
                ),Gaps.vGap5
              ],
            ),
          ))
        ],
      ),

    );
  }
}
